citation()
#Code for processing first street data
library(rspatial)
library(PerformanceAnalytics)
library(ggpubr)
library(dplyr)
library(ggplot2)
library(Hmisc)
library(corrplot)
library(sf)
library(sp)
library(tidyverse)
library(tidycensus)
library(tmap)
library(spdep)
library(tigris)
library(rmapshaper)
library(broom)
library(car)
library(spatialreg)
library(knitr)
library(stargazer)
library(RColorBrewer)
library(stats)
library(ape)
library(GWmodel)
library(lctools)
windowsFonts()
phoenixParcels <- read.csv("C:/Users/J/Documents/FirstStreet/Phoenix/RCode/PhoenixParcelsVariables_wHOLC.csv")
phoenixParcels_spearman <- phoenixParcels[,c(14, 22, 15, 20, 21, 25, 26)]
colnames(phoenixParcels_spearman) <- c("Flood factor", "Change in flood risk", "Building value", "Green cover", "Impervious cover", "Building age", "Redline")
#Code for processing first street data
library(rspatial)
library(PerformanceAnalytics)
library(ggpubr)
library(dplyr)
library(ggplot2)
library(Hmisc)
library(corrplot)
library(sf)
library(sp)
library(tidyverse)
library(tidycensus)
library(tmap)
library(spdep)
library(tigris)
library(rmapshaper)
library(broom)
library(car)
library(spatialreg)
library(knitr)
library(stargazer)
library(RColorBrewer)
library(stats)
library(ape)
library(GWmodel)
library(lctools)
windowsFonts()
install.packages("rspatial")
options(promt="R >", digits = 4, scipen = 7)
library(rgdal)
baltimore_shape <- readOGR(dsn = "C:/Users/J/Documents/FirstStreet/Baltimore/RCode/Shapefiles", layer = "CBG_Baltimore")
View(baltimore_shape)
library(sf)
library(purrr)
#Participant1
HR<- c(60,62,61,60,60,61)
Code<- c("0_0", "0_1", "1_1", "0_2", "2_2", "0_0")
Lat <- c("1.295824", "1.295824", "1.295826", "1.295828", "1.295830", "1.295830")
Lon <- c("103.8494", "103.8494", "103.8494", "103.8494", "103.8494", "103.8494")
P1 <- data.frame(HR, Code, Lat, Lon)
#Participant2
HR<- c(71,70,69,71,72, 70)
Code<- c("0_0", "0_1", "1_1", "1_1", "0_2", "2_2")
Lat <- c("1.295995", "1.295977", "1.295995", "1.295992", "1.295987", "1.295992")
Lon <- c("103.8492", "103.8492", "103.8492", "103.8492", "103.8492", "103.8492")
P2 <- data.frame(HR, Code, Lat, Lon)
#Participant3
HR<- c(68,67,65,66,68, 68)
Code<- c("0_0", "0_1", "1_1", "0_2", "2_2", "2_2")
P3 <- data.frame(HR, Code, Lat, Lon)
Lat <- c("1.295773", "1.295770", "1.295769", "1.295769", "1.295772",  "1.295769")
Lon <- c("103.8493", "103.8493", "103.8493", "103.8493", "103.8493", "103.8493")
#Creating a list of df from participant data
ListP <- list(P1, P2, P3)
ListP <- lapply(ListP, function(x)  sf::st_as_sf(x, coords=c("Lat","Lon"))) # creating geometry from latitude and longitude
View(ListP)
ListP
Tair <- c(30, 31, 32, 30, 21)
Code<- c("0_0", "0_1", "1_1", "0_2", "2_2")
Lat <- c("1.296033", "1.296028", "1.296020","1.296013", "1.296008")
Lon <- c("103.8493", "103.8493", "103.8493", "103.8493", "103.8493")
Weather <- data.frame(Tair, Code, Lat, Lon)
Weather <- sf::st_as_sf(Weather, coords = c("Lat","Lon"))# creating geometry from latitude and longitude
i = 1
ListP[[i]]
ListP[[i]] <- merge(ListP[[i]], Weather, by="Code", x.all = T)
#Code for processing first street data
library(rspatial)
library(PerformanceAnalytics)
library(ggpubr)
library(dplyr)
library(ggplot2)
library(Hmisc)
library(corrplot)
library(sf)
library(sp)
library(tidyverse)
library(tidycensus)
library(tmap)
library(spdep)
library(tigris)
library(rmapshaper)
library(broom)
library(car)
library(spatialreg)
library(knitr)
library(stargazer)
library(RColorBrewer)
library(stats)
library(ape)
library(GWmodel)
library(lctools)
library(rspatial)
library(rgdal)
library(MASS)
library(sf)
library(tidyverse)
library(tidycensus)
library(tmap)
library(spdep)
library(tigris)
library(rmapshaper)
library(broom)
library(car)
library(spatialreg)
library(knitr)
library(stargazer)
library(MuMIn)
#Setting Times New Roman as font
windowsFonts()
options(promt="R >", digits = 4, scipen = 7)
setwd("C:/Users/J/Documents/FirstStreet/Phoenix/RCode")
###CBG, whole city
phoenix <- read.csv("C:/Users/J/Documents/FirstStreet/Phoenix/RCode/CBG_Phoenix_D_Updated.csv")
##Phoenix, AZ
setwd("C:/Users/J/Documents/FirstStreet/DataSharing/RCode")
phoenix <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/PHX_CBG.csv")
phoenix_CBG <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/PHX_CBG.csv")
phoenixCBG <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/PHX_CBG.csv")
View(phoenixCBG)
phoenixCBG_spearman <- phoenixCBG[,c(21, 22, 4, 6, 3, 10, 8, 9, 12, 20, 7, 14, 23, 16, 15, 17, 18, 19)]
phoenixCBG_spearman <- phoenixCBG_spearman[complete.cases(phoenixCBG_spearman),]
####Spearman's Rank for CBG
colorsForPlot <- colorRampPalette(c("#88bbbe", "white", "#E24E3C"))
phoenixCBG_spearman_2 <- rcorr(as.matrix(phoenixCBG_spearman), type = "spearman")
phoenixParcels <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/PHX_Parcels.csv")
View(phoenixParcels)
phoenixParcels_spearman <- phoenixParcels[,c(2, 6, 3, 7, 4)]
colnames(phoenixParcels_spearman) <- c("Flood factor", "Change in flood risk", "Building value", "Building age", "Green cover")
phoenixParcels_spearman <- phoenixParcels_spearman[complete.cases(phoenixParcels_spearman),]
phoenixParcels_spearman_2 <-rcorr(as.matrix(phoenixParcels_spearman), type = "spearman")
phoenixParcels_inHOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/PHX_Parcels_HOLC.csv")
View(phoenixParcels_inHOLC)
phoenixParcels_inHOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/PHX_Parcels_HOLC.csv")
phoenixParcels_inHOLC_spearman <- phoenixParcels_inHOLC[,c(2, 6, 8)
phoenixParcels_inHOLC_spearman <- phoenixParcels_inHOLC[,c(2, 6, 8)]
phoenixParcels_inHOLC_spearman <- phoenixParcels_inHOLC[,c(2, 6, 8)]
View(phoenixParcels_inHOLC_spearman)
phoenixParcels_inHOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/PHX_Parcels_HOLC.csv")
phoenixParcels_inHOLC_spearman <- phoenixParcels_inHOLC[,c(2, 6, 8)]
colnames(phoenixParcels_inHOLC_spearman) <- c("Flood factor", "Change in chance", "Redline")
phoenixParcels_inHOLC_spearman <- phoenixParcels_inHOLC_spearman[complete.cases(phoenixParcels_inHOLC_spearman),]
phoenixParcels_inHOLC_spearman_2 <- rcorr(as.matrix(phoenixParcels_inHOLC_spearman), type = "spearman")
###CBGs in HOLC, for Spearman's Rank
phoenixCBG_HOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/PHX_CBG_HOLC.csv")
phoenixCBG_HOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/PHX_CBG_HOLC.csv")
View(phoenixCBG_HOLC)
phoenixCBG_HOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/PHX_CBG_HOLC.csv")
phoenixCBG_HOLC <- phoenixCBG_HOLC[,c(21, 22, 25, 26, 27)]
phoenixCBG_HOLC$Redline <- phoenixCBG_HOLC$sum_holc_d/phoenixCBG_HOLC$HOLCParcels
#Portland
portland <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/PDX_CBG.csv")
PDX_CBG <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/PDX_CBG.csv")
View(PDX_CBG)
portlandCBG_spearman <- PDX_CBG[,c(22, 23, 4, 3, 6, 17, 15, 16, 19, 20, 14, 8, 21, 10, 9, 11, 12, 13)]
portlandCBG_spearman <- portlandCBG_spearman[complete.cases(portlandCBG_spearman),]
portlandCBG_spearman <- portlandCBG_spearman[which(portlandCBG_spearman$FF > 0), ]
portlandCBG_spearman <- PDX_CBG[,c(22, 23, 4, 3, 6, 17, 15, 16, 19, 20, 14, 8, 21, 10, 9, 11, 12, 13)]
portlandCBG_spearman <- portlandCBG_spearman[complete.cases(portlandCBG_spearman),]
portlandCBG_spearman <- portlandCBG_spearman[which(portlandCBG_spearman$FF > 0), ]
portlandCBG_spearman <- PDX_CBG[,c(22, 23, 4, 3, 6, 17, 15, 16, 19, 20, 14, 8, 21, 10, 9, 11, 12, 13)]
portlandCBG_spearman <- portlandCBG_spearman[complete.cases(portlandCBG_spearman),]
portlandCBG_spearman <- portlandCBG_spearman[which(portlandCBG_spearman$mean_floodfactor > 0), ]
##Analysis of parcels
portlandParcels <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/PDX_Parcels.csv")
##Analysis of parcels
PDX_Parcels <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/PDX_Parcels.csv")
View(PDX_Parcels)
portlandParcels_spearman <- PDX_Parcels[,c(9, 3, 7, 2, 10)]
portlandParcels_spearman <- portlandParcels_spearman[complete.cases(portlandParcels_spearman),]
portlandParcels_spearman_2 <-rcorr(as.matrix(portlandParcels_spearman), type = "spearman")
##Analysis of parcels in HOLC
portlandParcels_HOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/PDX_Parcels_HOLC.csv")
PDX_Parcels_HOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/PDX_Parcels_HOLC.csv")
View(PDX_Parcels_HOLC)
portlandParcels_HOLC_spearman <- portlandParcels_HOLC[,c(11, 5, 14)]
portlandParcels_HOLC_spearman <- portlandParcels_HOLC_spearman[complete.cases(portlandParcels_HOLC_spearman),]
portlandParcels_HOLC_spearman_2 <-rcorr(as.matrix(portlandParcels_HOLC_spearman), type = "spearman")
corrplot(portlandParcels_HOLC_spearman_2$r, method = "color", type = "lower", order = "alphabet",
p.mat = portlandParcels_HOLC_spearman_2$P, sig.level = 0.001, insig = "blank", col = colorsForPlot(10),
diag = FALSE, tl.srt = 45, tl.col = "black", family = "serif")
##CBGs in HOLC
portlandCBG_HOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/PDX_CBG_HOLC.csv")
View(portlandCBG_HOLC)
portlandCBG_HOLC_spearman <- portlandCBG_HOLC[,c(23, 24, 26, 27)]
View(portlandCBG_HOLC_spearman)
portlandCBG_HOLC_spearman$Redline <- portlandCBG_HOLC_spearman$sum_holc_grade_d / portlandCBG_HOLC_spearman$InHOLC_Count
portlandCBG_HOLC_spearman <- portlandCBG_HOLC_spearman[complete.cases(portlandCBG_HOLC_spearman),]
#Baltimore
setwd("C:/Users/J/Documents/FirstStreet/DataSharing/RCode")
BMORE_CBG <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/BMORE_CBG.csv")
View(BMORE_CBG)
BMORE_CBG <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/BMORE_CBG.csv")
View(BMORE_CBG)
BMORE_CBG <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/BMORE_CBG.csv")
View(BMORE_CBG)
baltimoreCBG_spearman <- BMORE_CBG[,c(24, 25, 6, 3, 4, 8, 10, 22, 11, 12, 9, 16, 23, 18, 17, 19, 20, 21)]
baltimoreCBG_spearman <- baltimoreCBG_spearman[complete.cases(baltimoreCBG_spearman),]
##Baltimore analysis for CBGs
baltimoreParcels <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/BMORE_Parcels.csv")
BMORE_Parcels <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/BMORE_Parcels.csv")
View(baltimoreParcels)
baltimoreParcels_spearman <- BMORE_Parcels[,c(7, 10, 9, 3, 4)]
baltimoreParcels_spearman <- baltimoreParcels_spearman[complete.cases(baltimoreParcels_spearman),]
baltimoreParcels_spearman_2 <-rcorr(as.matrix(baltimoreParcels_spearman), type = "spearman")
##Baltimore analysis for parcels in HOLC
baltimoreParcels_inHOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/BMORE_Parcels_HOLC.csv")
View(baltimoreParcels_spearman)
View(baltimoreParcels_inHOLC)
baltimoreParcels_inHOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/BMORE_Parcels_HOLC.csv")
baltimoreParcels_inHOLC_spearman <- baltimoreParcels_inHOLC[,c(7, 10, 11)]
View(baltimoreParcels_inHOLC_spearman)
baltimoreParcels_inHOLC_spearman <- baltimoreParcels_inHOLC_spearman[complete.cases(baltimoreParcels_inHOLC_spearman),]
baltimoreParcels_inHOLC_spearman_2 <-rcorr(as.matrix(baltimoreParcels_inHOLC_spearman), type = "spearman")
###Doing HOLC analysis for CBG
baltimoreCBG_inHOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/BMORE_CBG_HOLC.csv")
View(baltimoreCBG_inHOLC)
baltimoreCBG_inHOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/BMORE_CBG_HOLC.csv")
baltimoreCBG_inHOLC_spearman <- baltimoreCBG_inHOLC[,c(24, 25, 29, 30)]
baltimoreCBG_inHOLC_spearman <- baltimoreCBG_inHOLC_spearman[complete.cases(baltimoreCBG_inHOLC_spearman),]
#Atlanta
setwd("C:/Users/J/Documents/FirstStreet/DataSharing/RCode")
ATL_CBG <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/ATL_CBG.csv")
View(ATL_CBG)
ATL_CBG <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/ATL_CBG.csv")
atlantaCBG_spearman <- ATL_CBG[,c(24, 25, 3, 4, 7, 6, 8, 20, 18, 19, 14, 12, 23, 13, 15, 16, 17, 28)]
ATL_CBG <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/ATL_CBG.csv")
atlantaCBG_spearman <- ATL_CBG[,c(24, 25, 4, 3, 6, 7, 8, 18, 19, 20, 12, 23, 14, 13, 15, 16, 17)]
atlantaCBG_spearman <- atlantaCBG_spearman[complete.cases(atlantaCBG_spearman),]
atlantaCBG_spearman_2 <- rcorr(as.matrix(atlantaCBG_spearman))
atlantaCBG_HOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/ATL_CBG_HOLC.csv")
ATL_CBG_HOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/ATL_CBG_HOLC.csv")
View(ATL_CBG_HOLC)
ATL_CBG_HOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/ATL_CBG_HOLC.csv")
atlantaCBG_HOLC_spearman <- ATL_CBG_HOLC[,c(21, 22, 23, 24, 25)]
atlantaCBG_HOLC_spearman <- atlantaCBG_HOLC_spearman[complete.cases(atlantaCBG_HOLC_spearman), ]
atlantaCBG_HOLC_spearman$Redline <- atlantaCBG_HOLC_spearman$sum_holc_d/atlantaCBG_HOLC_spearman$HOLCParcels_Count
ATL_CBG_HOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/ATL_CBG_HOLC.csv")
atlantaCBG_HOLC_spearman <- ATL_CBG_HOLC[,c(21, 22, 23, 24, 25)]
atlantaCBG_HOLC_spearman <- atlantaCBG_HOLC_spearman[complete.cases(atlantaCBG_HOLC_spearman), ]
atlantaCBG_HOLC_spearman <- ATL_CBG_HOLC[,c(21, 22, 23, 24, 25, 26)]
atlantaCBG_HOLC_spearman <- atlantaCBG_HOLC_spearman[complete.cases(atlantaCBG_HOLC_spearman), ]
atlantaCBG_HOLC_spearman$Redline <- atlantaCBG_HOLC_spearman$sum_holc_d/atlantaCBG_HOLC_spearman$HOLCParcels_Count
atlantaCBG_HOLC_25_spearman <- atlantaCBG_HOLC_spearman[which(atlantaCBG_HOLC_spearman$PropParcelsInHOLC >= 0.25),]
atlantaCBG_HOLC_25_spearman <- atlantaCBG_HOLC_25_spearman[,c(1, 2, 7)]
##Using only CBGs for which the proportion of parcels in the HOLC are 25% or greater
atlantaCBG_HOLC_25_spearman <- atlantaCBG_HOLC_spearman[which(atlantaCBG_HOLC_spearman$ParcelsInHOLC_prop >= 0.25),]
##Atlanta parcels analysis
atlantaParcels <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/ATL_Parcels.csv")
##Atlanta parcels analysis
ATL_Parcels <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/ATL_Parcels.csv")
View(ATL_Parcels)
View(ATL_Parcels)
atlantaParcels_spearman <- atlantaParcels[,c(7, 9, 5, 8)]
colnames(atlantaParcels_spearman) <- c("Flood factor", "Change in flood risk", "Green cover", "Building age")
atlantaParcels_spearman <- atlantaParcels_spearman[complete.cases(atlantaParcels_spearman),]
atlantaParcels_spearman_2 <-rcorr(as.matrix(atlantaParcels_spearman), type = "spearman")
##Atlanta parcels in HOLC analysis
atlantaParcels_inHOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/ATL_Parcels_HOLC.csv")
ATL_Parcels <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/ATL_Parcels.csv")
atlantaParcels_spearman <- ATL_Parcels[,c(7, 9, 5, 8)]
ATL_Parcels_inHOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/ATL_Parcels_HOLC.csv")
View(ATL_Parcels_inHOLC)
ATL_Parcels_inHOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/ATL_Parcels_HOLC.csv")
atlantaParcels_inHOLC <- ATL_Parcels_HOLC[,c(8, 10, 11)]
atlantaParcels_inHOLC_spearman <- atlantaParcels_inHOLC[complete.cases(atlantaParcels_inHOLC),]
atlantaParcels_inHOLC_spearman_2 <-rcorr(as.matrix(atlantaParcels_inHOLC_spearman), type = "spearman")
ATL_Parcels_HOLC <- read.csv("C:/Users/J/Documents/FirstStreet/DataSharing/RCode/ATL_Parcels_HOLC.csv")
atlantaParcels_inHOLC <- ATL_Parcels_HOLC[,c(8, 10, 11)]
atlantaParcels_inHOLC_spearman <- atlantaParcels_inHOLC[complete.cases(atlantaParcels_inHOLC),]
atlantaParcels_inHOLC_spearman_2 <-rcorr(as.matrix(atlantaParcels_inHOLC_spearman), type = "spearman")
colorsForPlot <- colorRampPalette(c("#88bbbe", "white", "#E24E3C"))
